package com.cdream.basic.algorithm.leetcode.string;

public class Question14 {
    public String longestCommonPrefix(String[] strs) {
        if(strs.length==0){
            return "";
        }
        int l = 0;
        int smallLength = Integer.MAX_VALUE;
        String base = strs[0];
        for (String str : strs) {
            smallLength = Math.min(smallLength,str.length());
        }
        for (int i = 0; i < smallLength; i++) {
            char j = base.charAt(i);
            for (String str : strs) {
                if (str.charAt(i)!=j){
                    return base.substring(0,l);
                }
            }
            l++;
        }
        return base.substring(0,smallLength);

    }

    public static void main(String[] args) {
        new Question14().longestCommonPrefix(new String[]{"flower","flow","flight"});
    }
}
